package com.ms.tank.fire;

import com.ms.tank.enums.Dir;
import com.ms.tank.enums.Group;
import com.ms.tank.game.Bullet;
import com.ms.tank.game.Tank;
import com.ms.tank.utils.Audio;

/**
 * 四方开火策略
 * @Date 2021/3/18 17:09:13
 * @Author mashuai
 */
public class FourDirFireStrategy implements FireStrategy{
    @Override
    public void fire(Tank tank) {
        //开火时调用子弹 子弹从中心发出
        int bx = tank.x + Tank.WIDTH / 2 - Bullet.WIDTH / 2;
        int by = tank.y + Tank.HEIGHT / 2 - Bullet.HEIGHT / 2;
        Dir[] dirs = Dir.values();
        for(Dir dir : dirs) {
           tank.tankFrame.gameFactory.createBullet(bx, by, dir, tank.group, tank.tankFrame);
        }
        if (tank.group == Group.GOOD) new Thread(() -> new Audio("audio/tank_fire.wav").play()).start();
    }
}
